/*
 * Copyright (c) 2022.版权所有高金磊
 */

package 领扣算法.AA中等题.游戏中弱角色的数量;


import java.util.Arrays;
import java.util.Comparator;

public class Main {
    public int numberOfWeakCharacters(int[][] properties) {
        Arrays.sort(properties,new Comparator<int[]>(){

            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0]==o2[0])
                    return o2[1]-o1[1];
                else
                    return o2[0]-o1[0];
            }
        });


        int max_value=Integer.MIN_VALUE,pre_max=properties[0][1];
        properties[0][1]=0;
        for (int i = 1; i <properties.length ; i++) {
            if (properties[i][0]<properties[i-1][0]){
                max_value=pre_max;
                pre_max=Math.max(properties[i][1],pre_max);

            }
            if (max_value>properties[i][1])
                properties[0][1]++;

        }
        return properties[0][1];
    }
}
